 document.write('<div id="blogger_archives_list">loading...</div>');
if(_root_ == undefined){
	var _root_ = {}
}
_root_._url = 'http://www.waylon.tk/';
_root_.paras = function(s){
	var o = {};
	if(s.indexOf('?') == -1) return {};
	var vs = s.split('?')[1].split('&');
	for(var i=0;i<vs.length;i++){
		if(vs[i].indexOf('=') != -1){
			var k = vs[i].split('=');
			eval('o.'+k[0]+'="'+k[1]+'"');
		}
	}
	return o;
}

_root_.load = function (func){
	if(document.all){  
		window.attachEvent('onload', func); 
	}  
	else{  
		window.addEventListener('load', func, false);  
	}
}

_root_.getSciprt = function(s){
	var script = document.createElement('script');
	script.src = s;
	script.type = 'text/javascript';
	document.getElementsByTagName('head')[0].appendChild(script);
}

_root_.init = function(){
	_root_.dom = document.getElementById('blogger_archives_list');
	var archives_obj = _root_.paras(document.getElementById('archives_widget_js').src);
	_root_._url = 'http://' + document.domain + '/';
	if(archives_obj.num){
		_root_.getSciprt(_root_._url + 'feeds/posts/summary?max-results=' + archives_obj.num + '&alt=json-in-script&callback=_root_.loadarchives');
	}
	else{
		_root_.getSciprt(_root_._url + 'feeds/posts/summary?max-results=9999&alt=json-in-script&callback=_root_.loadarchives');
	}
}

_root_.expendArchFunc = function(index){
	var thisbox = document.getElementById('arch_ul_' + index);
	if(thisbox.style.display == 'none'){
		thisbox.style.display = 'block'
	}
	else{
		thisbox.style.display = 'none';
	}
}

_root_.loadarchives = function(resp){
	var items = resp.feed.entry;
	var a = (items[0].published.$t).substring(0,7);
	var b, str;
	str = '<p>Waylon从 ' + items[items.length - 1].published.$t.substring(0,10) + ' 起共写了 ' + items.length + ' 篇文章.</p>';
	str += '<h3><a href="' + _root_._url + a.replace('-','_') + '_01_archive.html">' + a + '</a><a href="javascript:;" class="expend_archives" onclick="expendArchFunc(0)">+</a></h3><ul id="arch_ul_0">';
	
	for(var i = 0; i < items.length; i++){
		b = (items[i].published.$t).substring(0,7);
		if(b != a){
			str += '</ul><h3><a href="' + _root_._url + b.replace('-','_') + '_01_archive.html">' + b + '</a><a href="javascript:;" class="expend_archives" onclick="_root_.expendArchFunc(' + i + ')">+</a></h3><ul style="display:none" id="arch_ul_' + i + '">';
			a = b;
		}
		str += '<li><a href="' + items[i].link[2].href + '">' + items[i].title['$t'] + '</a><span>' + items[i].published.$t.substring(5,10) + '</span></li>';
		
	}
	str +='</ul>';
	
	if(_root_._url != 'http://www.waylon.tk/'){
	 str += '<p>by<a href="http://www.waylon.tk">Waylon</a></p>';
	}
	_root_.dom.innerHTML = str;
}

_root_.load(_root_.init);
